/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2018
 */

package com.bm.console.business.impl;

import com.sys.object.common.page.PageBean;

import com.bm.console.business.WebMessageService;
import com.bm.console.pojo.WebMessage;
import com.bm.console.pojo.mapper.WebMessageMapper;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sys.object.common.page.PageBean;

@Service
public class WebMessageServiceImpl implements WebMessageService {

	@Autowired
	WebMessageMapper webMessageMapper;

	@Override
	public PageBean queryPageList(WebMessage entity, PageBean page) throws Exception {
		int rowCount = webMessageMapper.selectByPageCount(entity);
		page.setRowCount(rowCount);
		entity.setOffset(page.getStartRow());
		entity.setLimit(page.getPerpage());
		page.setList(webMessageMapper.selectByPage(entity));
		return page;
	}

	public WebMessage queryByPrimaryKey(Integer id) throws Exception {
		return webMessageMapper.selectByPrimaryKey(id);
	}

	public int saveOrUpdate(WebMessage entity) throws Exception {
		if (entity.getId() != null && entity.getId() > 0) {
			entity.setUpdateTime(new Date());
			if (entity.getIsView()) {
				entity.setViewTime(new Date());
			}
			return this.webMessageMapper.updateByPrimaryKeySelective(entity);
		}
		entity.setCreateTime(new Date());

		return this.webMessageMapper.insert(entity);
	}

	public int remove(Integer id) throws Exception {
		return this.webMessageMapper.deleteByPrimaryKey(id);
	}

	public int delete(Integer id) throws Exception {
		return this.webMessageMapper.deleteByPrimaryKey(id);
	}

	public int updateStatus(WebMessage entity) throws Exception {
		return this.webMessageMapper.updateByPrimaryKeySelective(entity);
	}

	public int updateStatus(String status, String[] ids) throws Exception {

		return 0;
	}

}
